<template>
  <div>
    <SearchForm
      @search="onSearch"
      @reset="onReset"
      :search-list="searchList"
      :search-params="searchParams"
    />

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-handle">
          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>
        </div>
        <div class="table-box">
          <el-table
            v-loading="loading"
            :data="tableData"
            row-key="id"
            border
            default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            element-loading-spinner="el-icon-loading"
            element-loading-background="rgba(255, 255, 255, 0.8)"
          >
            <el-table-column
              prop="name"
              label="名称"
              min-width="180"
            />
<!--            <el-table-column-->
<!--              prop="type"-->
<!--              label="类型"-->
<!--              width="100"-->
<!--            >-->
<!--              <template slot-scope="{row}">-->
<!--                <el-tag :type="getTypeTag(row.type)">{{ getTypeLabel(row.type) }}</el-tag>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column
              prop="code"
              label="编码"
              min-width="120"
            />
            <el-table-column
              label="操作"
              width="200"
              align="center"
              fixed="right"
            >
              <template slot-scope="{row}">
                <el-button type="text" @click="handleAddChild(row)">新增子级</el-button>
                <el-button type="text" @click="onEdit(row)">编辑</el-button>
                <el-button type="text" style="color: #F82222" @click="onDelete(row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>

<script>
import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";

export default {
  name: "DistrictManagement",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: {
        ...http.district,
        list: http.district.tree,
        page: undefined
      },
      searchList: [
        {
          label: '名称',
          prop: 'name',
          name: 'input',
          clearable: true
        },
      ],
      searchParams: {
        name: '',
      },
      defaultParams: {}
    }
  },
  methods: {
    handleAddChild(row) {
      this.$refs.addFormRef.open(null, row)
    }
  }
}
</script>

<style lang="scss" scoped>
.table-layout {
  margin-top: 20px;
  .table-handle {
    margin-bottom: 20px;
  }
  .table-box {
    margin-bottom: 20px;
  }
}
</style>
